import Mock from 'mockjs'
import qs from 'qs'

const random = Mock.Random;

function resp(code, message, data) {
    return {
        code,
        message,
        data
    }
}

Mock.mock(/\/user\/login/, 'post', req => {
    const {username, password} = qs.parse(req.body);
    if (username === 'admin' && password === '123456') {
        return resp(200, "登录成功", {
            id: random.id(), // 身份证号
            username: username,
            name: random.cname(),
            age: random.integer(18, 50),
            birth: random.datetime("yyyy-MM-dd"),
            addr: `${random.province()}${random.city()}${random.county()}`,
            email: random.email("qq.com"),
            title: random.ctitle(10, 15),
        })
    } else {
        return resp(0, "登录失败，密码错误", null)
    }
})